/**
 * Copyright 2014 the original author or authors. All rights reserved.
 */
package com.visionet.security.domain.entity;

import java.util.Set;

import javax.persistence.*;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.visionet.jumper.core.domain.entity.BaseEntity;
import com.visionet.security.base.enums.UserStatus;
import org.hibernate.annotations.Fetch;

/**
 * 用户
 * @author suxiaojing
 * @since 0.0.1
 */
@Entity(name="User")
@Table(
		name="t_user",
		uniqueConstraints= @UniqueConstraint(columnNames={"loginName"})
)
@Cacheable
@DynamicInsert
@DynamicUpdate
public class User extends BaseEntity {

	private static final long serialVersionUID = 7667468879710265127L;

	private String name;

	private String loginName;

	private String password;

	@Enumerated(EnumType.STRING)
	private UserStatus status = UserStatus.AVAILABLE;

	private String salt;

	private String mail;

	private String mobile;

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "t_user_role",
			   joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
			   inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")}
			   )
	private Set<Role> roles;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public UserStatus getStatus() {
		return status;
	}

	public void setStatus(UserStatus status) {
		this.status = status;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	/**
	 * @return the roles
	 */
	public Set<Role> getRoles() {
		return roles;
	}

	/**
	 * @param roles
	 *            the roles to set
	 */
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
}
